package com.zsy.springframework.beans.factory.beanfactory;

import com.zsy.springframework.beans.factory.chouxiang.AbstractAutowireCapableBeanFactory;
import com.zsy.springframework.beans.factory.config.BeanDefinition;
import com.zsy.springframework.beans.factory.exception.BeansException;
import com.zsy.springframework.beans.factory.jiekou.BeanDefinitionRegistry;

import java.util.HashMap;
import java.util.Map;

//作用：保存bean的信息， 注册beandefinition 的信息到map当中 是个beanfactory的工厂
public class DefalutListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {
    private final Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    @Override
    public void registryBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }

    @Override
    protected BeanDefinition getBeanDefinition(String beanName) {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null) throw new BeansException("No bean named '" + beanName + "' is defined");
        return beanDefinition;
    }
}
